import { SecTimer } from "../../core/frame/SecTimer";
import { TimerType } from "../../core/frame/TimerType";
type int = number;
//class GameClock
    
    export  class GameClock /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.mouseChildren = false;
            this.mouseEnabled = false;
            this._label = new Object /* flash.text.TextField */();
            this._label.mouseEnabled = false;
            this._label.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._label.defaultTextFormat = new Object /* flash.text.TextFormat */(null, 12);
            this.addChild(this._label);
            this._secTimer = new SecTimer();
            this._secTimer.addListener(TimerType.ENTERFRAME, this.onEnterFrameHandler);
            return;
        }

        public get nowDate(): Date
        {
            if (!this._nowDate) 
            {
                this._nowDate = new Date();
            }
            return this._nowDate;
        }

        /* internal  */onEnterFrameHandler(arg1: SecTimer): void
        {
            this._nowDate.seconds = this._nowDate.seconds + 1;
            if (this.parent) 
            {
                this._label.text = this.getDateStr();
            }
            if (typeof this.enterFrameHandler === "function") 
            {
                this.enterFrameHandler(this._nowDate);
            }
            return;
        }

        public set time(arg1: Object)
        {
            if (typeof arg1 === "date") 
            {
                this._nowDate = arg1 as Date;
            }
            else if (typeof arg1 === "number") 
            {
                this._time = arg1 as number;
                this._nowDate = new Date(this._time);
            }
            if (this._secTimer.running == false) 
            {
                this._secTimer.start();
            }
            return;
        }

        /* internal  */getDateStr(): string
        {
            var loc1="";
            loc1 = loc1 + (this._nowDate.fullYear + "-");
            if (this._nowDate.month < 10) 
            {
                loc1 = loc1 + "0";
            }
            loc1 = loc1 + (this._nowDate.month + 1 + "-");
            if (this._nowDate.date < 10) 
            {
                loc1 = loc1 + "0";
            }
            loc1 = loc1 + (this._nowDate.date + "  ");
            if (this._nowDate.hours < 10) 
            {
                loc1 = loc1 + "0";
            }
            loc1 = loc1 + (this._nowDate.hours + ":");
            if (this._nowDate.minutes < 10) 
            {
                loc1 = loc1 + "0";
            }
            loc1 = loc1 + (this._nowDate.minutes + ":");
            if (this._nowDate.seconds < 10) 
            {
                loc1 = loc1 + "0";
            }
            loc1 = loc1 + this._nowDate.seconds;
            return loc1;
        }

        private /* var */_year: int;

        private /* var */_month: int;

        private /* var */_date: int;

        private /* var */_hours: int;

        private /* var */_minutes: int;

        private /* var */_seconds: int;

        private /* var */_time: number;

        private /* var */_nowDate: Date;

        private /* var */_secTimer: SecTimer;

        private /* var */_label: Object /* flash.text.TextField */;

        public /* var */enterFrameHandler: Function;
    }
